import server from "../utils/request.js";

/**
 * 按社区查询巡更点位
 * @param {Number} communityId - 社区ID
 * @returns Promise
 */
export function getPointByCommunity(communityId) {
    return server({
        url: '/patrol/point/list',
        method: 'GET',
        params: { communityId}
    })
}

/**
 * 按路线查询巡更点位
 * @param {Number} routeId - 路线ID
 * @returns Promise
 */
export function getPointByRoute(routeId) {
    return server({
        url: '/patrol/point/byRoute',
        method: 'GET',
        params: { routeId }
    })
}

/**
 * 添加巡更点位
 * @param {Object} point - 巡更点位信息
 * @returns Promise
 */
export function addPoint(point) {
    return server({
        url: '/patrol/point/add',
        method: 'POST',
        data: point
    })
}

/**
 * 更新巡更点位
 * @param {Object} point - 巡更点位信息
 * @returns Promise
 */
export function updatePoint(point) {
    return server({
        url: '/patrol/point/update',
        method: 'POST',
        data: point
    })
}

/**
 * 删除巡更点位
 * @param {Number} pointId - 点位ID
 * @returns Promise
 */
export function deletePoint(pointId) {
    return server({
        url: '/patrol/point/delete',
        method: 'GET',
        params: { pointId }
    })
}

export function getPointByCommunityWithQuery(communityId, query) {
    return server({
        url: '/patrol/point/list',
        method: 'GET',
        params: {
            communityId,
            query // 新增查询参数，与后端接口匹配
        }
    });
}



export function validateLocation(pointId, latitude, longitude) {
    return server({
        url: '/patrol/point/validateLocation',
        method: 'GET',
        params: {
            pointId,
            userLatitude: latitude,
            userLongitude: longitude
        }
    });
}



// 新增：获取点位的巡检记录（最近几次）
export const getPointCheckins = (params) => {
    return server({
        url: '/patrol/point/checkins', // 根据实际后端接口路径调整
        method: 'GET',
        params // 参数包含 pointId、pageSize 等
    });
};

// 新增：获取点位详情
export const getPointDetail = (pointId) => {
    return server({
        url: `/patrol/point/${pointId}`, // 根据实际后端接口路径调整
        method: 'GET'
    });
};
